package top.itaso.app.room.repository;

import androidx.lifecycle.LiveData;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import top.itaso.app.room.AppDatabase;
import top.itaso.app.room.dao.UserDao;
import top.itaso.app.room.entity.UserEntity;

/**
 * @Description:
 * @Author itsdf07
 * @E-Mail 923255742@qq.com
 * @Gitee https://gitee.com/itsdf07
 * @Date 2022/1/10
 */
public class UserRepository implements IUserRepository {
    private static UserRepository userRepository;
    private UserDao userDao;

    public static UserRepository getInstance() {
        if (userRepository == null) {
            synchronized (UserRepository.class) {
                if (userRepository == null) {
                    userRepository = new UserRepository();
                }
            }
        }
        return userRepository;
    }

    @Override
    public LiveData<List<UserEntity>> querys() {
        return userDao.querys();
    }

    @Override
    public UserEntity queryUserName(String username) {
        return userDao.queryUserName(username);
    }

    @Override
    public List<UserEntity> querysInUserNames(String[] userNames) {
        return userDao.querysInUserNames(userNames);
    }

    @Override
    public UserEntity queryUser(String username, String password) {
        return userDao.queryUser(username, password);
    }

    @Override
    public List<UserEntity> querysLikeDisplayName(String displayName) {
        return userDao.querysLikeDisplayName(displayName);
    }

    @Override
    public long[] inserts(UserEntity... users) {
        return userDao.inserts(users);
    }

    @Override
    public long insert(UserEntity user) {
        return userDao.insert(user);
    }

    @Override
    public int delete(UserEntity user) {
        return userDao.delete(user);
    }

    @Override
    public long update(UserEntity user) {
        return userDao.update(user);
    }

    @Override
    public int updateDisplayName(@NotNull String username, String displayName) {
        return userDao.updateDisplayName(username, displayName);
    }

    @Override
    public int updateState(@NotNull String uid, int state) {
        return userDao.updateState(uid, state);
    }

    private UserRepository() {
        userDao = AppDatabase.getInstance().userDao();
    }
}
